<?php if (!defined('THINK_PATH')) exit(); /*a:3:{s:50:"D:\webroot\tongji/app/admin\view\fos\buy_list.html";i:1543907949;s:49:"D:\webroot\tongji/app/admin\view\common\head.html";i:1535850094;s:49:"D:\webroot\tongji/app/admin\view\common\foot.html";i:1535850094;}*/ ?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title><?php echo config('sys_name'); ?>后台管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
  
  <script>
  /^http(s*):\/\//.test(location.href) || alert('请先部署到 localhost 下再访问');
  </script>
</head>

<style>
.layui-btn{line-height:28px !important;}
</style>
<div class="layui-fluid"><div class="layui-card"><div class="layui-card-body">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>购买记录</legend>
    </fieldset>
    <div class="demoTable">
        <div class="layui-inline">
            <input class="layui-input" name="key" id="key" placeholder="<?php echo lang('pleaseEnter'); ?>关键字">
        </div>
        <button class="layui-btn" id="search" data-type="reload"><?php echo lang('search'); ?></button>
        <button type="button" class="layui-btn layui-btn-danger" id="delAll">批量删除</button>
        
        <div style="clear: both;"></div>
    </div>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
</div>
</div>
<script src="/layuiadmin/layui/layui.js"></script>  
<script type="text/html" id="name">
   {{# if(d.status==3){ }}
      <font color=red>{{d.name}}</font>
	{{# } else { }}
	  {{d.name}}
   {{# } }}
</script>
<script type="text/html" id="order">
    <input name="{{d.id}}" data-id="{{d.id}}" class="list_order layui-input" value=" {{d.sort}}" size="10"/>
</script>
<script type="text/html" id="status">
    {{# if(d.status==0){ }}
    <a class="layui-btn layui-btn-mini layui-btn-warm">待审核</a>
    {{# } }}
	 {{# if(d.status==1){ }}
    <a class="layui-btn layui-btn-mini layui-btn-danger">待审核</a>
    {{# } }}
	{{# if(d.status==2){ }}
    <a class="layui-btn layui-btn-mini">通过</a>
    {{# } }}
	{{# if(d.status==3){ }}
    <a class="layui-btn layui-btn-mini layui-btn-danger">拒绝</a>
    {{# } }}
</script>

<script type="text/html" id="pay_type">
    {{# if(d.pay_type==0){ }}
    支付宝
    {{# } }}
	 {{# if(d.pay_type==1){ }}
    银行卡
    {{# } }}
	{{# if(d.pay_type==2){ }}
    微信
    {{# } }}
</script>
<script type="text/html" id="action">
   {{# if(d.status == 1){ }}
	<?php if($group_id == 2): ?>
        <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="twice_pass">审核</a>
	<?php endif; ?>
	{{# }}}
	
	{{# if(d.status == 0){ }}
	<?php if($group_id == 3): ?>
	<a class="layui-btn layui-btn-mini" lay-event="first_pass">确认</a>
	<?php endif; ?>
	{{# }}}
</script>


<script>
    layui.use('table', function() {
        var table = layui.table, $ = layui.jquery;
        var tableIn = table.render({
            id: 'ad',
            elem: '#list',
            url: '<?php echo url("buy_list"); ?>',
            method: 'post',
            page:true,
            cols: [[
                {checkbox: true, fixed: true},
                {field: 'id', title: '<?php echo lang("id"); ?>', width: 80, fixed: true},
                {field: 'name', title: '会员名称', width: 100,templet: '#name'},
                {field: 'count', title: '购买数量', width: 100},
                {field: 'money', title: '购买金额', width: 100},
                {field: 'shop', title: '二维码商家',width: 150},
                {field: 'pay_type', title: '支付方式',width: 150, templet:'#pay_type'},
                {field: 'code', title: '参考码',width: 150},
                {field: 'add_time', title: '申购时间',width: 180},
                {field: 'limit', title: '购买限额',width: 180},
                {field: 'status', title: '状态',width: 150, templet:'#status'},
                {width: 160, align: 'center', toolbar: '#action'}
            ]],
            limit:10
        });
        //搜索
        $('#search').on('click', function () {
            var key = $('#key').val();
            if ($.trim(key) == '') {
                layer.msg('<?php echo lang("pleaseEnter"); ?>关键字！', {icon: 0});
                return;
            }
            tableIn.reload({
                where: {key: key}
            });
        });
        table.on('tool(list)', function(obj) {
            var data = obj.data;
            if (obj.event == 'open') {
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post('<?php echo url("editState"); ?>', {'id': data.id}, function (res) {
                    layer.close(loading);
                    if (res.status == 1) {
                        if (res.open == 1) {
                            obj.update({
                                open: '<a class="layui-btn layui-btn-mini layui-btn-warm" lay-event="open">开启</a>'
                            });
                        } else {
                            obj.update({
                                open: '<a class="layui-btn layui-btn-mini layui-btn-danger" lay-event="open">禁用</a>'
                            });
                        }
                    } else {
                        layer.msg('操作失败！', {time: 1000, icon: 2});
                        return false;
                    }
                })
            }else if(obj.event == 'del'){
                layer.confirm('您确定要删除该商家吗？', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("<?php echo url('del'); ?>",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code==1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg('操作失败！',{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }else if(obj.event == 'first_pass'){  //初审
			    layer.confirm('您确定通过吗？', {btn: ['通过','拒绝', '取消']}, function(index){
					var loading = layer.load(1, {shade: [0.1, '#fff']});
					$.post("<?php echo url('first_pass'); ?>",{id:data.id,status:1},function(res){
						layer.close(loading);
						if(res==1){
							layer.msg(res.msg,{time:1000,icon:1});
							tableIn.reload();
						}else if(res == -99){
						    layer.msg('超过限额！',{time:1000,icon:2});
						}else{
							layer.msg('操作失败！',{time:1000,icon:2});
						}
					});
					layer.close(index);
				}, function(index){
					var loading = layer.load(1, {shade: [0.1, '#fff']});
					$.post("<?php echo url('twice_pass'); ?>",{id:data.id,status:3},function(res){
						layer.close(loading);
						if(res==1){
							layer.msg(res.msg,{time:1000,icon:1});
							tableIn.reload();
						}else{
							layer.msg('操作失败！',{time:1000,icon:2});
						}
					});
					layer.close(index);
				});
			}else if(obj.event == 'twice_pass'){  //二审
				layer.confirm('您确定通过审核吗？', {btn: ['通过','拒绝', '取消']}, function(index){
					var loading = layer.load(1, {shade: [0.1, '#fff']});
					$.post("<?php echo url('twice_pass'); ?>",{id:data.id,status:2},function(res){
						layer.close(loading);
						if(res==1){
							layer.msg(res.msg,{time:1000,icon:1});
							tableIn.reload();
						}else if(res == -99){
						    layer.msg('超过限额！',{time:1000,icon:2});
						}else{
							layer.msg('操作失败！',{time:1000,icon:2});
						}
					});
					layer.close(index);
				}, function(index){
					var loading = layer.load(1, {shade: [0.1, '#fff']});
					$.post("<?php echo url('twice_pass'); ?>",{id:data.id,status:3},function(res){
						layer.close(loading);
						if(res==1){
							layer.msg(res.msg,{time:1000,icon:1});
							tableIn.reload();
						}else{
							layer.msg('操作失败！',{time:1000,icon:2});
						}
					});
					layer.close(index);
				});
			}
        });
        $('body').on('blur','.list_order',function() {
            var id = $(this).attr('data-id');
            var sort = $(this).val();
            var loading = layer.load(1, {shade: [0.1, '#fff']});
            $.post('<?php echo url("adOrder"); ?>',{id:id,sort:sort},function(res){
                layer.close(loading);
                if(res.code == 1){
                    layer.msg(res.msg, {time: 1000, icon: 1});
                    tableIn.reload();
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            })
        });
        $('#delAll').click(function(){
            layer.confirm('确认要删除选中的商家吗？', {icon: 3}, function(index) {
                layer.close(index);
                var checkStatus = table.checkStatus('ad'); //test即为参数id设定的值
                var ids = [];
                $(checkStatus.data).each(function (i, o) {
                    ids.push(o.id);
                });
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("<?php echo url('delall'); ?>", {ids: ids}, function (data) {
                    layer.close(loading);
                    if (data.code == 1) {
                        layer.msg(data.msg, {time: 1000, icon: 1});
                        tableIn.reload();
                    } else {
                        layer.msg(data.msg, {time: 1000, icon: 2});
                    }
                });
            });
        })
    })
</script>